package lc;
import util.*;
import java.util.*;

import org.junit.Test;

public class Ex242 {
    class Solution {
        public boolean isAnagram(String s, String t) {
            Map<Character, Integer> map = new HashMap<>();
            char[] ss = s.toCharArray(), ts = t.toCharArray();
            for (int i = 0; i < ss.length; i++) {
                map.put(ss[i], map.getOrDefault(ss[i], 0) + 1);
            }
            System.out.println(map);
            for (int i = 0; i < ts.length; i++) {
                if (!map.containsKey(ts[i])) {
                    System.out.println(ts[i]);
                    return false;
                }
                int cur = map.get(ts[i]);
                if (cur == 1) {
                    map.remove(ts[i]);
                } else {
                    map.put(ts[i], cur - 1);
                }
            }
            return map.isEmpty();
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        System.out.println(s.isAnagram(
            "dgqztusjuu",
            "dqugjzutsu"));        
    }
}
